//
//  MyImageTableViewCell.m
//  ZAKER
//
//  Created by dllo on 15/8/31.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "MyImageTableViewCell.h"

@implementation MyImageTableViewCell

-(void)dealloc
{
    
    [_text release];
    [_image_urls release];
    [_string release];
    
    [super dealloc];
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.image_urls = [[[UIImageView alloc]init] autorelease];
        [self.contentView addSubview:_image_urls];
        _image_urls.backgroundColor = [UIColor redColor];
//        [_image_urls release];
        
        self.text = [[[UILabel alloc]init] autorelease];
        _text.numberOfLines = 0;
        _text.textColor = [UIColor grayColor];
        [self.contentView addSubview:_text];
//        [_text release];

    }
    
    return self;
    
}

- (void)setString:(NSString *)string
{
    
    if (_string != string) {
        
        [_string release];
        _string = [string retain];
        
    }
    
    CGFloat h = [[self class] heightWityImage:self.image_urls.image];
    CGFloat texth = [[self class] heightWthText:_string];
    CGRect frame = self.frame;
    
    self.text.frame = CGRectMake(10 * myWidth, 100, frame.size.width + 30 * myWidth,  texth);
    self.image_urls.frame = CGRectMake(0, 0, frame.size.width + 55 * myWidth, h);
    frame.size = CGSizeMake(frame.size.width, h + texth);
    self.frame = frame;
    
}

#pragma mark - 照片和文字的自适应高读方法

+ (CGFloat)heightWityImage:(UIImage *)myImage
{
    
    return  myImage.size.height;
    
}

+(CGFloat)heightWthText:(NSString *)text
{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(355 *  myWidth, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    
    return rect.size.height;
    
}
- (void)awakeFromNib
{

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    
    [super setSelected:selected animated:animated];

}

@end
